package com.xmg.leetCode;

import lombok.val;

/**
 * @Author: mazhongqing
 * @Date: 2021/3/16 19:52
 */
public class No19 {
}

class Solution19 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        if(head==null || head.next==null){
            return null;
        }
        ListNode dummy =  new ListNode(0,head);
        ListNode left = dummy;
        ListNode right =left;
        while (true){
            for(int i = 0;i < n+1;i++){
                right = right.next;

            }
            while (right!=null){
                left = left.next;
                right = right.next;
            }
            left.next = left.next.next;
            break;
        }
        return dummy.next;
    }
}
